﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace HML.Demo
{
    public partial class AnomalyButtonForm : ItemFormTemplate
    {
        public AnomalyButtonForm()
        {
            InitializeComponent();
            this.Load += new System.EventHandler(this.Form_Load);
            this.Shown += new System.EventHandler(this.Form_Shown);
        }

        #region 实现

        public override ItemFormTemplateViewObject AsynchRequestTask(ItemFormTemplateViewObject view)
        {
            System.Threading.Thread.Sleep(300);
            view.ViewData = DemoHelper.GetDescription(AppDomain.CurrentDomain.BaseDirectory + "例子\\控件\\AnomalyButtonForm\\AnomalyButtonForm.rtf");
            return view;
        }

        public override void DataBind(ItemFormTemplateViewObject viewObject)
        {
            this.introduceBrowser.Rtf = viewObject.ViewData.ToString();
        }

        public override void ShowView()
        {
            base.ShowView();
        }

        public override void HideView()
        {
            base.HideView();
        }

        public override void CloseView()
        {
            base.CloseView();
        }

        #endregion

        #region 属性面板

        private void Form_Load(object sender, EventArgs e)
        {
            this.controlContainer.SizeChanged += this.ControlContainer_SizeChanged;

            this.demo_control.CheckButton = false;
            this.demo_control.Location = new Point((this.controlContainer.Width - this.demo_control.Width) / 2, (this.controlContainer.Height - this.demo_control.Height) / 2);
            this.demo_control.StylePattern = AnomalyButtonStylePattern.Bezier;
            this.demo_control.ShapePoints = "{10.19,22.95} {60.77,58.73} {105.75,22.89} {109.14,58.5} {193.09,8.68} {115.14,100.41} {57.83,101.1}";

            this.checkButton_toggleSwitch.IsOn = this.demo_control.CheckButton;
            this.checkButton_toggleSwitch.Toggled += this.CheckButton_toggleSwitch_Toggled; ;

            this.transitionMode_dropDownListPlus.Multiple = false;
            this.transitionMode_dropDownListPlus.BindEnumList<AnomalyButtonStylePattern>(this.demo_control.StylePattern);
            this.transitionMode_dropDownListPlus.SelectedItemsChanged += this.StylePattern_dropDownListPlus_SelectedItemsChanged; ;

            this.shapeItems_textBox.Text = this.demo_control.ShapePoints;
            this.shapeItems_textBox.LostFocus += this.ShapeItems_textBox_LostFocus;
        }

        private void Form_Shown(object sender, EventArgs e)
        {
            this.splitContainer.SplitterDistance = Math.Max(this.splitContainer.Width / 4, this.splitContainer.Width - MainForm.GlobalSplitWidth);
            this.splitContainer.SplitterMoved += this.SplitContainer_SplitterMoved;

            MainForm.LoadAssistTabControl(this.assistTabControl);
        }

        private void SplitContainer_SplitterMoved(object sender, SplitterEventArgs e)
        {
            SplitContainer control = (SplitContainer)sender;
            MainForm.GlobalSplitWidth = this.splitContainer.Width - control.SplitterDistance;
        }

        private void ControlContainer_SizeChanged(object sender, EventArgs e)
        {
            Panel control = (Panel)sender;
            this.demo_control.Location = new Point((control.Width - this.demo_control.Width) / 2, (control.Height - this.demo_control.Height) / 2);
        }

        private void CheckButton_toggleSwitch_Toggled(object sender, EventArgs e)
        {
            ToggleSwitch control = (ToggleSwitch)sender;
            this.demo_control.CheckButton = control.IsOn;
        }

        private void StylePattern_dropDownListPlus_SelectedItemsChanged(object sender, EventArgs e)
        {
            DropDownListPlus control = (DropDownListPlus)sender;
            this.demo_control.StylePattern = (AnomalyButtonStylePattern)control.SelectedItem.Tag;
        }

        private void ShapeItems_textBox_LostFocus(object sender, EventArgs e)
        {
            string str = this.shapeItems_textBox.Text.Trim();
            if (str != this.demo_control.ShapePoints)
            {
                this.demo_control.ShapePoints = str;
            }
        }

        #endregion
    }
}
